package com.wcsy.myblog.controller;

import com.wcsy.myblog.entity.JsonResult;
import com.wcsy.myblog.entity.Type;
import com.wcsy.myblog.entity.User;
import com.wcsy.myblog.service.ITypeService;
import com.wcsy.myblog.service.serviceImpl.NumServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 类型信息
 */
@RestController
@RequestMapping("/type")
@CrossOrigin
@Api(description = "类型信息")
@ApiModel
public class TypeController {
    @Autowired
    private ITypeService iTypeService;
    @Autowired
    HttpSession session;
    @Autowired
    NumServiceImpl numService;

    /**
     * @apiNote 添加文章类型
     * @param typeName 父级文章类型名称
     * @param typeKidName 子级文章类型名称
     * @return
     */
    @ApiOperation("添加文章类型")
    @GetMapping("/insert")
    public JsonResult insert(String typeName,String typeKidName){
        if (typeName ==null){
             typeName="-1";
        }else if (typeKidName ==null){
            typeKidName ="-1";
        }
       try {
           iTypeService.insertType(typeName, typeKidName);
           return new JsonResult(200,"添加成功","");
       } catch (Exception e) {
           e.printStackTrace();
           return new JsonResult(500,"添加失败!请勿输入敏感词汇","");
       }
   }
    /**
     * @apiNote 查询出用户的分类文章信息
     * @param userId 用户id
     * @return
     */
    @ApiOperation("查询出用户的分类文章信息")
   @GetMapping("selectOneList")
   public JsonResult selectOneList(int userId){
        try {
            List<Type> types = iTypeService.selectOneList(userId);
            return new JsonResult(200,"查询成功",types);
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult(500,"查询失败","");
        }
   }
}
